#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#define MAX_SIZE 10000
typedef struct User
{
    int id;
    int score[5];
    int sum_score;
    int full_p;
    bool submit;
} ArrayUser[MAX_SIZE];

int compare2key(const void *a, const void *b)
{ /* 比较两种键值：按key1非升序排列；如果key1相等，则按key2非降序排列 */
    int k;
    if ( ((const User *)a)->sum_score < ((const User *)b)->sum_score )
        k = 1;
    else if ( ((const User *)a)->sum_score > ((const User *)b)->sum_score )
        k = -1;
    else 
    { /* 如果key1相等 */
        if ( ((const User *)a)->full_p < ((const User *)b)->full_p)
            k = 1;
        else if ( ((const User *)a)->full_p > ((const User *)b)->full_p)
            k = -1;
        else
        {
            if ( ((const User *)a)->id < ((const User *)b)->id)
                k = -1;
            else
                k = 1;
        }
    }
    return k;
}
int main()
{
    int N, K, M, full_mark[5], user_id, p_id, p_score;
    ArrayUser all_user;
    scanf("%d %d %d", &N, &K, &M);
    for (int i = 0; i < K; i++)
        scanf("%d", &full_mark[i]);

    // init
    for (int i = 0; i < N; i++)
    {
        all_user[i].sum_score = 0;
        all_user[i].full_p = 0;
        all_user[i].id = i + 1;
        all_user[i].submit = false;
        for (int j = 0; j < K; j++)
            all_user[i].score[j] = -1; // non-visited
    }
    // init

    for (int i = 0; i < M; i++)
    {
        scanf("%d %d %d", &user_id, &p_id, &p_score);
        if (all_user[--user_id].score[--p_id] <= p_score)
        {
            all_user[user_id].score[p_id] = p_score > 0 ? p_score : 0;
            if (p_score > -1)
                all_user[user_id].submit = true;
        }
    }

    // 重新整体计算 分数总和和满分题目
    for (int i = 0; i < N; i++)
        for (int j = 0; j < K; j++)
            if (all_user[i].score[j] > 0)
            {
                if (all_user[i].score[j] == full_mark[j])
                    all_user[i].full_p++;
                all_user[i].sum_score += all_user[i].score[j];
            }
            

    qsort(all_user, N, sizeof(User), compare2key);

    int LastScore = all_user[0].sum_score, LastRank = 1;
    for (int i = 0; i < N; i++)
    {
        if(all_user[i].submit)
        {
            // 当分数不相等时，需要更新一个记录到last
            if (LastScore != all_user[i].sum_score)
            {
                LastScore = all_user[i].sum_score;
                LastRank = i + 1;
            }
            printf("%d %05d %d", LastRank, all_user[i].id, all_user[i].sum_score);
            for (int j = 0; j < K; j++)
            {
                if (all_user[i].score[j] >= 0)
                    printf(" %d", all_user[i].score[j]);
                else
                    printf(" -");

                if (j == (K - 1))
                    printf("\n");
            }
        }

    }
    return 0;
}